import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:flutter_staggered_grid_view/flutter_staggered_grid_view.dart';
import 'package:ytbusiness/utils/helper.dart';
import 'package:ytbusiness/utils/screen_adaptation.dart';

import '../../routes.dart';

/// 我的订单
class OrderWidget extends StatefulWidget {
  final List<String> numList;
  final List<String> titleList;

  const OrderWidget({Key key, this.numList, this.titleList}) : super(key: key);

  @override
  _OrderWidgetState createState() => _OrderWidgetState();
}

class _OrderWidgetState extends State<OrderWidget> {
  bool isShow = false; //默认隐藏

  @override
  Widget build(BuildContext context) {
    return Container(
      color: Colors.white,
      padding: EdgeInsets.only(
          top: setWidth(15),
          left: setWidth(15),
          right: setWidth(15),
          bottom: setWidth(15)),
      child: Column(
        mainAxisAlignment: MainAxisAlignment.start,
        crossAxisAlignment: CrossAxisAlignment.start,
        children: [
          _allOrder("全部订单"),
          Container(
            margin: EdgeInsets.only(top: setWidth(15), bottom: setWidth(30)),
            height: setWidth(0.5),
            color: Color(0xffF0F0F0),
          ),
          Container(
              child: StaggeredGridView.countBuilder(
            physics: NeverScrollableScrollPhysics(),
            shrinkWrap: true,
            crossAxisCount: 3,
            mainAxisSpacing: setWidth(30),
            crossAxisSpacing: setWidth(30),
            staggeredTileBuilder: (i) {
              return StaggeredTile.fit(1);
            },
            itemCount: widget.numList.length,
            itemBuilder: (context, index) {
              return GestureDetector(
                  behavior: HitTestBehavior.opaque,
                  onTap: () {
                    urlPush(
                        context,
                        RouteManager.route(
                            RouteManager.orderList + "?label=1"));
                  },
                  child: _gridItem(
                      widget.numList[index], widget.titleList[index]));
            },
          )),
        ],
      ),
    );
  }

  Container _gridItem(String num, String title) {
    return Container(
      child: Column(
        children: [
          Container(
            child: Text(title,
                style: TextStyle(
                  color: Color(0xff666666),
                  fontSize: setSp(14),
                )),
          ),
          SizedBox(
            height: setWidth(18),
          ),
          Container(
              child: RichText(
                  text: TextSpan(children: [
            TextSpan(
                text: num,
                style: TextStyle(
                    color: Color(0xff323232),
                    fontSize: setSp(24),
                    fontWeight: FontWeight.w600)),
            TextSpan(
                text: " (笔)",
                style: TextStyle(color: Color(0xff999999), fontSize: setSp(12)))
          ]))),
        ],
      ),
    );
  }

  _allOrder(String title) {
    return GestureDetector(
      onTap: () {
        print("点击 全部订单。。。");
        urlPush(
            context, RouteManager.route(RouteManager.orderList + "?label=1"));
      },
      child: Row(
        children: [
          Expanded(
              child: Container(
            child: Text(
              title,
              style: TextStyle(
                  color: Color(0xFF323232),
                  fontSize: setSp(15),
                  fontWeight: FontWeight.w700),
            ),
          )),
          Container(
            child: Image.asset("assets/images/pay_go.png",
                width: setWidth(9), height: setWidth(16), fit: BoxFit.cover),
          ),
        ],
      ),
    );
  }
}
